#!/bin/bash

#=======================================================================
# mailview
# File ID: 6366b35e-f743-11dd-8a05-000475e441b9
# Konverter greier i ISO-8859-1 til UTF-8 før det vises med w3m(1).
# License: GNU General Public License version 2 or later.
#=======================================================================

file="$@"
tmpfile=/tmp/mailview.`uuid`.html

# echo `l "$file"`
cat "$file" >$tmpfile

find_inv_utf8 -q $tmpfile
found_invalid=$?

if [ "$found_invalid" = "1" ]; then
    # echo Før recode: `l $tmpfile`
    recode ISO-8859-1..UTF-8 <$tmpfile >$tmpfile.tmp
    # echo Etter recode: `l $tmpfile.tmp`
    mv $tmpfile.tmp $tmpfile
fi

# echo Før w3m: `l $tmpfile`
/usr/bin/w3m -dump -T text/html "$tmpfile"
# /usr/bin/lynx -dump "$tmpfile"
# /usr/bin/elinks -dump "$tmpfile"
# echo Etter w3m: `l $tmpfile`

rm $tmpfile
